package org.example.service.impl;

import org.example.service.IRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service

public class RedisServiceImpl implements IRedisService {
    @Autowired
    @Qualifier("redisTemplate1")
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    @Qualifier("stringRedisTemplate")
    private StringRedisTemplate myStringRedisTemplate;



    @Override
    @Transactional
    public Long testTransactionAnnotations() {
        return myStringRedisTemplate.opsForValue().increment("count", 1);
    }

    @Override
    @Transactional
    public Long increaseCounterError(String key) {
        return redisTemplate.opsForValue().increment(key,5);
    }
    @Override
    public void testRedisMulti() {
        myStringRedisTemplate.setEnableTransactionSupport(true);
        myStringRedisTemplate.multi();
        myStringRedisTemplate.opsForValue().set("{a}passjava", "123");
        myStringRedisTemplate.opsForValue().set("{a}悟空聊架构", "abc");
        myStringRedisTemplate.exec();
    }

}
